package com.bulemobi.activity.ac_user_centre;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.bulemobi.net.tsz.afinal.FinalHttp;
import com.bulemobi.net.tsz.afinal.annotation.view.ViewInject;
import com.bulemobi.net.tsz.afinal.http.AjaxCallBack;
import com.bulemobi.net.tsz.afinal.http.AjaxParams;
import com.bulemobi.urlCentre.UrlCentre;
import com.bulemobi.util.MD5Util;
import com.bulemobi.view.BaseActivity;
import com.bulemobi.view.CardMessageView;
import com.bulemobi.view.titleView.ActionBarView;
import com.jsyh.hcb.R;

import java.security.NoSuchAlgorithmException;

/**
 * @author zengys  车辆信息
 *         <p/>
 *         <p/>
 *         2014年9月18日 12:59:57
 */
public class CarMessageActivity extends BaseActivity implements View.OnClickListener {
    CardMessageView view;
    @ViewInject(id = R.id.actionBar)
    ActionBarView actionBarView;
    @ViewInject(id = R.id.btn_confirm)
    Button btn_confirm;
    private String carNo;
    private String mobile;
    private String markType;
    private String engine_no;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_card_message);
        findActionBar();
        initData();
    }

    private void initData() {
        Intent intent = getIntent();
        mobile = intent.getStringExtra("mobile");
        carNo = intent.getStringExtra("carNo");
        markType = intent.getStringExtra("markType");
        engine_no = intent.getStringExtra("engine_no");
        AjaxParams params = new AjaxParams();
        String value = UrlCentre.APPSECRET + "plate_type" + markType + "plate_no" +
                carNo + "engine_no" + engine_no + "mobile" + mobile + "appkey"+UrlCentre.APPKEY+UrlCentre.APPSECRET;
        String sign = "";
        try {
            sign = MD5Util.encodeByMD5(value);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        params.put("appkey", UrlCentre.APPKEY);
        params.put("sign_method", "MD5");
        params.put("timestamp", AddCarActivity.getNowDate());
        params.put("sign", sign);
        Log.d("dasdasdasdasdasd","dasdasdasasdas");
        requestHttp(UrlCentre.VEHICLE, params, "init");
    }

    private void requestHttp(String url, AjaxParams params, final String type) {
        FinalHttp http = new FinalHttp();
        http.get(url, params, new AjaxCallBack<Object>() {
            @Override
            public void onStart() {
                showProgressDialog();
                super.onStart();
            }

            @Override
            public void onSuccess(Object o) {
                closeProgressDialog();
                Log.d("onSuccessCarMsg",o.toString());
                if (type.equals("init")) {
                    Log.d("OnSuccessInit", o.toString());
                } else {
                    Log.d("OnSuccess", o.toString());
                }
                super.onSuccess(o);
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                closeProgressDialog();
                Log.d("asdasdasdasdasda",strMsg);
                super.onFailure(t, errorNo, strMsg);
            }
        });
    }

    private void findActionBar() {
        actionBarView.title.setText(getResources().getText(R.string.card_info));
        btn_confirm.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
            case R.id.btn_confirm:
                openActivity(Ac_MyCar.class);
                finish();
                break;
            default:
                break;
        }

    }

}
